package com.wcl.demo.ui.activity;

import android.graphics.Paint;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.easemob.EMCallBack;
import com.easemob.chat.EMChatManager;
import com.easemob.chat.EMGroupManager;
import com.easemob.util.NetUtils;
import com.wcl.demo.R;
import com.wcl.demo.presenter.LoginPresenter;
import com.wcl.demo.ui.ViewInterface.ViewLoginInterface;
import com.wcl.demo.utils.ActivityUtils;
import com.wcl.demo.view.CustomToast;
import com.wcl.demo.utils.ProgressUtils;

import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Created by dllo on 15/11/18.
 */
public class LoginActivity extends MVPBaseActivity<ViewLoginInterface, LoginPresenter> implements ViewLoginInterface {

    @Bind(R.id.login_difficult)
    TextView login_difficult;
    @Bind(R.id.login_username)
    EditText login_username;
    @Bind(R.id.login_password)
    EditText login_password;
    @Bind(R.id.login_login)
    Button login_login;

    @Override
    protected int getLayout() {
        return R.layout.activity_login;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {
        login_difficult.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
    }

    @OnClick(R.id.login_back)
    void login_back() {
        finish();
    }

    @OnClick(R.id.login_login)
    void login_login() {
        //点击注册按钮实现注册功能
        login();
    }

    @OnClick(R.id.login_difficult)
    public void setLogin_difficult() {
        ActivityUtils.startToActivity(this, RegisterActivity.class);
    }

    /****
     * 登录
     */

    public void login() {
        ProgressUtils.showProgress(this);
        Map<String, String> map = new HashMap<>();
        final String loginUsername = login_username.getText().toString().trim();
        String loginPsw = login_password.getText().toString().trim();
        map.put("loginUsername", loginUsername);
        map.put("loginPsw", loginPsw);
        createPresenter().startLogin(map);
    }

    @Override
    protected LoginPresenter createPresenter() {
        return new LoginPresenter(this);
    }

    @Override
    public void showLoginResult(String str) {
        ProgressUtils.dismissProgress();
        ActivityUtils.startToActivity(LoginActivity.this, MainActivity.class);
        finish();
    }
}
